/**
 * meiguang8.com
 * Copyright (C) 2016-2019 All Rights Reserved.
 */
package com.yuanchuang.yp.mall.web.admin.controller.user;

import com.yuanchuang.yp.framework.common.CommonResult;
import com.yuanchuang.yp.mall.web.admin.controller.BaseController;
import com.yuanchuang.yp.mall.web.admin.entity.AuthUserDO;
import com.yuanchuang.yp.mall.web.admin.user.model.MenuModel;
import com.yuanchuang.yp.mall.web.admin.user.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * class_name: MenuController
 * package: com.yuanchuang.yp.mall.web.admin.controller.auth
 * describe: TODO
 * @author: yuanyuan.zhu
 * creat_date: 2019/7/12
 * creat_time: 13:06
 **/
@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {
    @Autowired
    private AuthService authService;

    @Autowired
    private HttpServletRequest httpServletRequest;

    @GetMapping("/list")
    public CommonResult listMenus(){
        AuthUserDO authUser = getAuthUser(httpServletRequest);
        List<MenuModel> menuModels = authService.listMenus(authUser.getId());
        return CommonResult.ok(menuModels);
    }

    @GetMapping("/tree/list")
    public  CommonResult treeMenus(){
        AuthUserDO authUser = getAuthUser(httpServletRequest);
        return CommonResult.ok(authService.listMenuTree(authUser.getId()));
    }
}
